Set a breakpoint in managed code if the method has not been JIT-compiled
Comments: If you need to set a breakpoint on the first time through a function, this might present a problem, because the code will not be JIT-compiled until right before it is executed.  To work around this issue, follow these steps.
Step 1: Find the MethodDesc for a given function
0:003> !Name2EE basedebug.exe basedebug.MyMain.MyFunction
--------------------------------------
MethodDesc: 375080
Name: [DEFAULT] String basedebug.MyMain.MyFunction()
-----------------------
Step 2: Dump the MethodDesc for the function.
0:003> !DumpMD 375080
Method Name : [DEFAULT] String basedebug.MyMain.MyFunction()
MethodTable 375098
Module: 14ea50
mdToken: 06000002 (G:\Projects\VC\basedebug\bin\Debug\basedebug.exe)
Flags : 10
IL RVA : 00002088
Note: The DumpMD command outputs "IL RVA : 00002088", which means that this method has not yet been JIT-compiled.  You cannot actually set a breakpoint until the method has been JIT-compiled, because you do not have a memory address for the breakpoint.
Step 3: Set a breakpoint for when the method gets JIT'ed
0:003> ba w4 375080+4
Note: If you dump out the MethodDesc structure:
0:003> dt MethodDesc 375080
   +0x000 m_wSlotNumber    : 5
   +0x002 m_wFlags         : 0x10
   +0x004 m_CodeOrIL       : 0x80002088
the m_CodeOrIL member field indicates whether the code has been JIT-compiled.  When the code is JIT-compiled, the member field is set to the address of the JIT-compiled code. This is why you must set a breakpoint when you write to this memory address.
Step 4: Once your code hits this breakpoint, the method should have be JIT-compiled.
0:003> g
Breakpoint 0 hit
eax=031241a8 ebx=00000000 ecx=0012f778 edx=00000014 esi=00375080 edi=0014f0f8
eip=791e83d0 esp=0012f674 ebp=0012f788 iopl=0         nv up ei pl zr na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
mscorwks!MakeJitWorker+458:
791e83d0 895f24           mov     [edi+0x24],ebx    ds:0023:0014f11c=00000001

0:000> !DumpMD 375080
Method Name : [DEFAULT] String basedebug.MyMain.MyFunction()
MethodTable 375098
Module: 14ea50
mdToken: 06000002 (G:\Projects\VC\basedebug\bin\Debug\basedebug.exe)
Flags : 10
Method VA : 031241a8
Note: When you use the DumpMD command, note that it now outputs "Method VA : 031241a8". This indicates that the method has been JIT-compiled and you can set a breakpoint on this memory address.
Step 5: Set the breakpoint
0:003> bp 031241a8